package com.hgl.servlet.admin;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hgl.entity.Hgl;
import com.hgl.service.HglService;
import com.hgl.service.impl.HglServiceImpl;
import com.hgl.vo.HglVO;

/**
 * 
 * @author:HGL
 * ClassName:com.hgl.servlet.admin.UserAddServlet.java
 * Date:2020年7月28日上午9:49:09
 * Version:1.0
 */
@WebServlet("/admin/user-add.let")
public class UserAddServlet extends HttpServlet{
	private HglService hglservice=new HglServiceImpl();

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		//获取参数
		SimpleDateFormat format=new SimpleDateFormat("yyyy-mm-dd");
		
		Hgl hgl=new Hgl();
		
		try {
			hgl.setHglName(request.getParameter("hglName"));
			hgl.setHglGrade(Integer.valueOf(request.getParameter("hglGrade")));
			hgl.setHglTel(request.getParameter("hglTel"));
			hgl.setHglBirth(format.parse(request.getParameter("hglBirth")));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//支持业务逻辑的接口
		//跳转到视图
		try{
			hglservice.add(hgl);
			request.setAttribute("msg", "添加用户成功");
			request.setAttribute("href", "admin/news-list.let");
			}catch(Exception ex){
				request.setAttribute("error", ex);
		}
			request.getRequestDispatcher("/admin/msg.jsp").forward(request, response);
		}

		
	}


